#!/usr/bin/Rscript
os <<- Sys.info()['sysname']

if(os == "Windows"){
  setwd("F:/cuffdiff/")
}else if(os == Linux){
  setwd("/home/zhang/BMK/test/cuffdiff/")
}

library(ggplot2)
library(openxlsx)

change.label <- function(input){
  if(input[4] == "lnc"){
    return("lncRNA")
  }else if(input[4] == "mrna"){
    return("mRNA")
  }else{
    return("microRNA")
  }
}


# 改变字体为Times New Roman
windowsFonts(NRM = windowsFont("Times New Roman"))
old_theme <- theme_update(axis.text = element_text(family = "NRM", size = 18, color = "black"),
                          legend.key.size = unit(1.2, "cm"),
                          axis.title = element_text(family = "NRM", size = 18),
                          legend.text = element_text(family = "NRM", size = 18))


test <- read.xlsx("mirandaBC_superdiff.xlsx", 2)
test$Type <- apply(test,1,change.label)
  
tiff("superdiff_density.tiff", width = 10, height = 8, compression = "lzw", units = "in", res = 600)
ggplot(data = test, aes(x = BC_normalized, colour = Type)) + geom_density() + xlab("Betweenness Centrality")
dev.off()


test <- read.xlsx("mirandaBC_diff.xlsx", 2)
test$Type <- apply(test,1,change.label)

tiff("diff_density.tiff", width = 10, height = 8, compression = "lzw", units = "in", res = 600)
ggplot(data = test, aes(x = BC_normalized, colour = Type)) + geom_density() + xlab("Betweenness Centrality")
dev.off()


test <- read.xlsx("mirandaBC.xlsx", 2)
test$Type <- apply(test,1,change.label)

tiff("all_density.tiff", width = 10, height = 8, compression = "lzw", units = "in", res = 600)
ggplot(data = test, aes(x = BC_normalized, colour = Type)) + geom_density() + xlab("Betweenness Centrality")
dev.off()

test <- read.xlsx("network/统计.xlsx", 6)
tiff("mirna_density.tiff", width = 10, height = 8, compression = "lzw", units = "in", res = 600)
ggplot(data = test, aes(x = BC_normalized)) + geom_density() + xlab("Betweenness Centrality")
dev.off()